define(function(require, exports, module) {
    'use strict';

    var $ = require('jquery');
    var Slider = require('plugins/slider');
    var LazyStream = require('plugins/lazystream');
    require('plugins/imgLoading');

    $('.jImg').imgLoading();

    if($('.jSliderImg').length>1){
        var slider = new Slider('#slides', {
            width:640,
            height:222,
            lazyLoad: {
                attr: 'data-url',
                loadingClass: 'img-error'
            },
            play: {
              auto: true,
              interval: 4000,
              swap: true,
              pauseOnHover: true,
              restartDelay: 2500
            },
            callback:{
                start:function(index){
                },
                loaded : function(){
                }
            }
        });
    }else{
        var el = $('.jSliderImg').eq(0);
        var src = el.attr('data-url');
        sliderImgLoad(src,el);
        $('#slides').addClass('ui-slider-one');
    }

    function sliderImgLoad(src,el) {
        if (isImgUrl(src)) {
            var objImg = new Image();
            objImg.src = src;
            if (objImg.complete) {
                el.attr('src',src).removeClass('img-error').removeAttr('data-url');
            } else {
                objImg.onload = function() {
                    el.attr('src',src).removeClass('img-error').removeAttr('data-url');
                };
            }
        }
    }

    function isImgUrl(str) {
        return (/^((https?|ftp|rmtp|mms):)?\/\/(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(:(\d+))?\/?/i).test(str);
    }

    function rem(value){
        return value/46.875+'rem';
    }

    var lazyMore = new LazyStream('.jPage', {
        plUrl: '/json/index-list.php',
        paramFormater: function(n) {
            var data = {};
            data.pageNo = n;
            return data;
        },
        page:2,
        errorText: '<div class="loading">网络错误，点击重试</div>',
        loadingClass: 'loading',
        loadingText: '<div class="loading"><img src="../../image/plugins/loading.gif" class="load-gif" />正在加载，请稍后...</div>',
        load: function(el) {
            $(el).find('.jImg').imgLoading();
        },
        noAnyMore:'<div class="loading">sorry,已经没有下一页了...</div>'
    });

    $('.jSearchIpt').focus(function(){
        $('.jSub').animate({left: rem(40)});
    });

    $('.jSearchIpt').keyup(function(){
        var self = this;
        if($.trim($(self).val()) == ""){
            $('.jSub').animate({left: rem(200)});
        }
    });

    $('.jSub').click(function(){
        $('#jSearchForm').submit();
    });

});
